const moveZeroes = function(nums) {
    // 双指针：快慢指针
    let slow = 0, len = nums.length;
    for (let i = 0; i < len; i++) {
        if (nums[i] != 0) {
            nums[slow] = nums[i];
            slow ++;
        }
    }
    // 剩余位置，置 0
    for (let j = slow; j < len; j++) {
        nums[j] = 0;
    }
    return nums;
};

const nums1 = [0, 1, 0, 3, 12];  // output: {1, 3, 12, 0, 0}
const nums2 = [1];  // output: {1}

let inputs = [];
inputs.push(nums1);
inputs.push(nums2);

for (let i = 0; i < inputs.length; i++) {
    const res = moveZeroes(inputs[i]);
    console.log(res);
}
